﻿
SET QUOTED_IDENTIFIER ON
GO

SET ANSI_NULLS ON
GO

IF ( OBJECT_ID(N'[dbo].[sproc_Mail_UpdateSMSStatus]', 'P') IS NOT NULL )
BEGIN
    DROP PROCEDURE [dbo].[sproc_Mail_UpdateSMSStatus]
END
GO
CREATE PROCEDURE [dbo].[sproc_Mail_UpdateSMSStatus]
	@mailStatus xml
AS
BEGIN
SET NOCOUNT ON;
SET XACT_ABORT ON;


/*
 * XML format
 * <mails>
 *  <m id="[integer]" status="[integer]" />
 * </mails>
 */

UPDATE m
SET m.SMSFlag = X.r.value(N'@status', N'int')
FROM dbo.UDS_Mail m INNER JOIN @mailStatus.nodes(N'/mails/m') X(r) ON m.MailId = X.r.value(N'@id', N'int')

END
GO
